package com.myz.app.service;

import com.myz.app.controller.UserControl;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.apache.shiro.session.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 * Created by maoyz on 17-10-11.
 */
@Service
public class ShiroService {
    private final static Logger logger = LoggerFactory.getLogger(UserControl.class);

    /**
     * 1 @RequiresRoles(value={“admin”, “user”}, logical= Logical.AND)
     * 2 @RequiresUser()
     *     表示当前Subject已经身份验证或者通过记住我登录的。
     * 3 @RequiresGuest()
     *     表示当前Subject没有身份验证或通过记住我登录过，即是游客身份。
     * 4 @RequiresAuthentication()
     *     表示当前Subject已经通过login进行了身份验证；即Subject.isAuthenticated()返回true。
     * 5 @RequiresPermissions(value={“user:a”, “user:b”}, logical= Logical.OR)
     */
    @RequiresRoles(value = {"admin"})
    public void testAnnotation(){
        logger.info("testAnnotation..");

        // session
        Session session = SecurityUtils.getSubject().getSession();
        // Shiro　Session接收HttpSession发送的消息
        Object msg = session.getAttribute("shiroSession");
        logger.info("Shiro session 接收HttpSession发送的消息..." + msg);

    }
}
